
//店铺授权之前购买服务确认


import React, { useEffect } from "react";
import CommonModal from '@/components/CommonModal';
import { Button, Form, Radio,  } from 'antd';
import { renderRoleType } from '@/utils/utils.jsx';
import useSettingStore from "@/stores/setting";

//获取用户角色类型
const roleType = renderRoleType();

const BuyConfirm = ({ visible, id, isJumpLogin, handleOk, handleCancel }) => {

	const title = useSettingStore(state => state.title);

  const [ form ] = Form.useForm();

  useEffect(() => {
    if(visible && id != 26) {
      form.resetFields();
    }
  }, [ visible ])

  //跳转到应用购买页面
  const handleBuyService = () => {
    const pathArr = [
      { id: '1', src: title == '易发货' ? 'https://fuwu.taobao.com/ser/detail.htm?service_code=FW_GOODS-1001122201&spm=a1z13.1113647.0.0.20cd5acaLk4YHV&code=FW_GOODS-1001122201': 'https://fuwu.taobao.com/ser/detail.htm?service_code=FW_GOODS-1000239806&code=FW_GOODS-1000239806' },
      { id: '2', src: 'https://fuwu.taobao.com/ser/detail.htm?service_code=FW_GOODS-1000239806&code=FW_GOODS-1000239806' },
      { id: '3', src: 'https://fw.jd.com/main/detail/FW_GOODS-258815' },
      { id: '4', src: 'https://mms.pinduoduo.com/login/sso?platform=fuwu&redirectUrl=https://fuwu.pinduoduo.com/clint/api/login?redirect=https://fuwu.pinduoduo.com/service-market/service-detail?detailId=4355', mall_src: 'https://fuwu.pinduoduo.com/service-market/service-detail?detailId=63011' },
      { id: '5', src: 'https://pc.1688.com/product/detail.htm?spm=0.0.0.0.DmsEFH&productCode=Zl%2FvMD0HQ%2FLTkZEflqusr%2Bc8EYpmLYzB5zze9GGLPN4%3D&productType=GROUP' },
      { id: '8', src: 'https://yingyong.youzan.com/cloud-app-detail/52238' },
      { id: '12', src: 'https://fuwu.kwaixiaodian.com/detail?id=938934573299' },
      { id: '14', src: 'https://fuwu.jinritemai.com/detail?from=open_partner_svcList&service_id=1965' },
      { id: '22', src: 'http://fuwu.suning.com/detail/1000101486.html' },
      { id: '26', src: 'https://fuwu.taobao.com/ser/detail.htm?service_code=FW_GOODS-1001122201' },
      { id: '40', src: 'https://www.xiaohongshu.com/explore' },
    ]
    let path;
    if(id == 4) {
      // if(isJumpLogin) {//商城pdd单独的授权应用
      //   path = pathArr.filter(v => v.id == id)[0].mall_src;
      // }  else {
      //   path = pathArr.filter(v => v.id == id)[0].src;
      // }
      path = pathArr.filter(v => v.id == id)[0].mall_src;//统一
    } else {
      path = pathArr.filter(v => v.id == id)[0].src;
    }
    window.open(path);
  }

  const handleClick = () => {
    form.validateFields().then(val => {
      handleOk(val)
    }).catch(() => {

    })
  }

  return (
    <CommonModal
      title='应用服务购买确认'
      visible={visible}
      width='600px'
      onCancel={handleCancel}
      footer={[
        <Button key='save' onClick={handleBuyService}>我未订购，去购买应用</Button>,
        <Button key='ok' onClick={handleClick} type='primary'>我已订购，开始授权</Button>
      ]}
    >
      <div className='common-color11' style={{ paddingLeft:  '24px' }}>
        <p style={{ marginBottom: '16px'}}>店铺授权前请先在服务市场购买应用服务，购买成功后才能授权店铺</p>
        {id != '26' && <Form 
            name='shop-authorize'
            className='search-form-style'
            form={form}
            style={{ marginBottom: 12 }}
            initialValues={{spdFlag: 1}}
          >
            <Form.Item 
              name="spdFlag"
              label="同步订单去往"
              rules={[
                { required: true, message: '同步订单去往未设置' },
              ]}
            >
              <Radio.Group>
                {/* {
                  roleType != 'zifa' && 
                  <Radio value={1} style={radioStyle}>
                    订单处理页面（自发、代发业务）
                  </Radio>
                }
                {
                  ((roleType == 'zjf' || roleType == 'zifa') && id != 22) &&
                  <Radio value={3} style={radioStyle}>
                    自发打印页面
                  </Radio>
                } */}
                <Radio value={1}>
                  订单处理页面（自发、代发业务）
                </Radio>
              </Radio.Group>
            </Form.Item>
          </Form>}
          {
            roleType == 'zjf' && id != '26' && <p className='common-color13'>注：授权店铺成功后，平台同步的订单会去往订单处理页面或自发打印页面，两者必须取其一，请谨慎选择自己所需的业务；如需修改可在店铺设置里修改选项，但是之前同步过的订单不能再修改</p>
          }
      </div>
    </CommonModal>
  );
};

export default BuyConfirm;